<!DOCTYPE html>
<html>
<head>
    <title>Setting `document.domain` to invalid values fails.</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script>
        test(function () {
            assert_equals(document.domain, '127.0.0.1');
            assert_throws_dom('SecurityError',
                              function () {
                                document.domain = null;
                              });
            assert_equals(document.domain, '127.0.0.1');
        }, 'Setting `document.domain` to null fails.');

        test(function () {
            assert_equals(document.domain, '127.0.0.1');
            assert_throws_dom('SecurityError',
                              function () {
                                document.domain = '';
                              });
            assert_equals(document.domain, '127.0.0.1');
        }, 'Setting `document.domain` to the empty string fails.');

        test(function () {
            assert_equals(document.domain, '127.0.0.1');
            assert_throws_dom('SecurityError',
                              function () {
                                document.domain = '0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001.1';
                              });
            assert_equals(document.domain, '127.0.0.1');
        }, 'Setting an invalid `document.domain` that looks like an IP address fails.');

        test(function () {
            assert_equals(document.domain, '127.0.0.1');
            assert_throws_dom('SecurityError',
                              function () {
                                document.domain = '[]';
                              });
            assert_throws_dom('SecurityError',
                              function () {
                                document.domain = 'example.test/path';
                              });
            assert_throws_dom('SecurityError',
                              function () {
                                document.domain = '%.com';
                              });
            assert_equals(document.domain, '127.0.0.1');
        }, 'Setting `document.domain` to a host that fails to parse fails.');
    </script>
</head>
